/**
 * @Description:
 * @Author BPF
 * @create 2021/11/5 9:26
 */
const fs = require('fs')
const path = require('path')
const { DefinePlugin } = require('webpack')
const defaultWebpackConfig = require('../../build/config')

const ROOT_PATH = path.resolve(__dirname, '../../')
const IS_PRO = process.env.NODE_ENV === 'production'

// 打包静态资源前缀
const BASE = IS_PRO ? '/fr/mandalat-ui/' : '/'

module.exports = {
  base: BASE,
  title: 'MandalaT-UI',
  description: '基于element实现的符合公司业务的ui框架，基于vue2.x的组件库',
  configureWebpack: (config, isServer) => {
    // 修改客户端的 webpack 配置
    config.resolve = {
      ...(config.resolve || {}),
      alias: {
        '~public': path.resolve(__dirname, 'public'), // 静态资源文件地址
        '~examples': path.resolve(ROOT_PATH, 'examples'),
        '~packages': path.resolve(ROOT_PATH, 'packages'),
        '~root': ROOT_PATH,
        ...config.resolve.alias,
        ...defaultWebpackConfig.alias
      },
      extensions: [...config.resolve.extensions, ...['.js', '.vue', '.json']]
    }
    config.module.rules.forEach(v => {
      if (v.test && v.test.test('.js')) {
        v.include = process.cwd()
        v.exclude.push(filepath => {
          if (/utils\/popper\.js|utils\/date\.js/.test(filepath.split(path.sep).join('/'))) return true
        })
      }
    })
    config.plugins.push(
      new DefinePlugin({
        BASE: JSON.stringify(BASE)
      })
    )
  },
  head: [
    [
      'link',
      {
        rel: 'icon',
        href: '/favicon.ico'
      }
    ],
    [
      'link',
      {
        rel: 'stylesheet',
        href: 'https://at.alicdn.com/t/font_2908936_pxggfiihcdf.css'
      }
    ]
  ],
  markdown: {
    lineNumbers: false
  },
  locales: {
    '/': {
      lang: 'zh-CN'
    }
  },
  themeConfig: {
    logo: `/images/logo-w.png`,
    search: true,
    smoothScroll: true,
    searchMaxSuggestions: 10,
    mdEnhance: {
      enableAll: false
    },
    nav: [
      // 导航栏
      { text: '首页', link: '/' },
      { text: '开发规范', link: '/design/' },
      { text: '基础组件', link: '/basic-components/' },
      { text: '业务组件', link: '/business-components/' },
      { text: '图表规范', link: '/chart/' },
      { text: '主题方案', link: '/theme/' },
      { text: '设计资源', link: '/resource/' }
    ],
    sidebar: {
      '/basic-components/': [
        {
          title: '开发指南',
          collapsable: false,
          children: ['', 'quickstart', 'custom-theme', 'transition']
        },
        {
          title: '基础',
          collapsable: false,
          children: ['layout', 'container', 'icon', 'button', 'link']
        },
        {
          title: '表单',
          collapsable: false,
          children: [
            'radio',
            'checkbox',
            'input',
            'input-number',
            'select',
            'cascader',
            'switch',
            'slider',
            'time-picker',
            'datetime-picker',
            'upload',
            'rate',
            'color-picker',
            'transfer',
            'form'
          ]
        },
        {
          title: '数据',
          collapsable: false,
          children: [
            'table',
            'tag',
            'progress',
            'tree',
            'pagination',
            'badge',
            'avatar',
            'skeleton',
            'empty',
            'descriptions',
            'result'
          ]
        },
        {
          title: '通知',
          collapsable: false,
          children: ['alert', 'loading', 'message', 'message-box', 'notification']
        },
        {
          title: '导航',
          collapsable: false,
          children: ['menu', 'tabs', 'breadcrumb', 'page-header', 'dropdown', 'steps']
        },
        {
          title: '其他',
          collapsable: false,
          children: [
            'dialog',
            'tooltip',
            'popover',
            'popconfirm',
            'card',
            'carousel',
            'collapse',
            'timeline',
            'divider',
            'calendar',
            'image',
            'backtop',
            'infiniteScroll',
            'drawer'
          ]
        }
      ],
      '/business-components/': [
        {
          title: '开始',
          collapsable: false,
          children: ['']
        },
        {
          title: '业务组件',
          collapsable: false,
          children: ['chose-regional']
        }
      ],
      '/chart/': [
        {
          title: '开始',
          collapsable: false,
          children: ['']
        }
      ]
    },
    sidebarDepth: 0,
    lastUpdated: '上次更新' // string | boolean
  },
  plugins: [
    [
      'vuepress-plugin-demo-container-v2',
      {
        component: 'DemoCode'
      }
    ],
    '@vuepress/plugin-back-to-top',
    [
      'vuepress-plugin-right-anchor', // 文档：https://github.com/xuekai-china/vuepress-plugin-right-anchor/blob/master/zh-README.md
      {
        showDepth: 3,
        ignore: ['/'],
        expand: {
          trigger: 'click',
          clickModeDefaultOpen: true
        },
        customClass: 'custom-anchor-plugin'
      }
    ],
    [
      '@vuepress/plugin-register-components',
      {
        componentsDir: [
          path.resolve(ROOT_PATH, './docs/.vuepress/components'),
          path.resolve(ROOT_PATH, './docs/.vuepress/components/page'),
          path.resolve(ROOT_PATH, './docs/.vuepress/components/basic-components'),
          path.resolve(ROOT_PATH, './docs/.vuepress/components/business-components')
        ]
      }
    ]
  ] // 插件
}
